import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { BuffInfo } from "./BuffInfo";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { DataEvent } from "../../events/DataEvent";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { SecTimerView } from "../common/SecTimerView";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { TState } from "../../../../Message/Db/Tables/TState";
type int = number;
//class BuffToolTip
    
    export  class BuffToolTip /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            Dispatcher.addEventListener(EventName.BuffRemainTimeUpdate, this.onBuffRemainTimeUpdateHandler);
            return;
        }

        public set data(arg1: BuffInfo)
        {
            var loc1=null;
            var loc2=0;
            this._buffInfo = arg1;
            if (arg1) 
            {
                loc1 = arg1.tstate;
                loc2 = arg1.getLeavSeconds();
            }
            this._tstate = loc1;
            if (loc1) 
            {
                this._nameTxt.htmlText = loc1.name;
                this._descTxt.htmlText = "<textFormat leading=\'5\'>" + loc1.description + "</textFormat>";
                if (loc1.category == 1 && !(loc1.lastTime == -1)) 
                {
                    if (!this.contains(this.leftTimeSprite)) 
                    {
                        this.addChild(this.leftTimeSprite);
                    }
                    this.leftTimeSprite.y = this._descTxt.y + this._descTxt.height;
                    if (loc2 > 3600) 
                    {
                        this._leftTimeView.setParse(Language.getString(53084));
                    }
                    else 
                    {
                        this._leftTimeView.setParse(Language.getString(50068));
                    }
                    this._leftTimeView.setLeftTime(loc2);
                }
                else if (this.contains(this.leftTimeSprite)) 
                {
                    this.removeChild(this.leftTimeSprite);
                }
            }
            return;
        }

        /* internal  */init(): void
        {
            this._nameTxt = ObjCreate.createTextField("", 0, 0, 220, 20, this, GlobalStyle.textFormat5);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._descTxt = ObjCreate.createTextField("", 0, 20, 220, 20, this, GlobalStyle.textFormat1);
            this._descTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._descTxt.multiline = true;
            return;
        }

        /* internal  */onSecViewTimeChangeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            if (loc1 == 0) 
            {
                if (this.contains(this.leftTimeSprite)) 
                {
                    this.removeChild(this.leftTimeSprite);
                }
            }
            return;
        }

        public onBuffRemainTimeUpdateHandler(arg1: DataEvent): void
        {
            var loc2=0;
            var loc3=0;
            var loc1=arg1.data as BuffInfo;
            if (loc1) 
            {
                loc2 = loc1.stateId;
                loc3 = loc1.getLeavSeconds();
            }
            if (this._tstate.stateId == loc2) 
            {
                if (loc3 > 3600) 
                {
                    this._leftTimeView.setParse(Language.getString(53084));
                }
                else 
                {
                    this._leftTimeView.setParse(Language.getString(50068));
                }
                this._leftTimeView.setLeftTime(loc3);
            }
            return;
        }

        public get leftTimeSprite(): Object /* flash.display.Sprite */
        {
            var loc1=null;
            var loc2=null;
            if (this._leftTimeSprite == null) 
            {
                loc1 = new GTextFormat(FontUtil.songtiName, 12, 16299783);
                loc1.align = flash.text.TextFormatAlign.LEFT;
                this._leftTimeSprite = new Object /* flash.display.Sprite */();
                this._leftTimeSprite.mouseEnabled = false;
                loc2 = ObjCreate.createTextField(Language.getString(50030), 0, 0, 220, 20, this._leftTimeSprite, loc1);
                loc2.autoSize = flash.text.TextFieldAutoSize.LEFT;
                this._leftTimeView = new SecTimerView();
                this._leftTimeView.autoSize = flash.text.TextFieldAutoSize.LEFT;
                this._leftTimeView.mouseEnabled = false;
                this._leftTimeView.defaultTextFormat = loc1;
                this._leftTimeView.filters = [FilterConst.glowFilter];
                this._leftTimeView.setParse(Language.getString(53084));
                this._leftTimeView.addEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChangeHandler);
                this._leftTimeView.x = 60;
                this._leftTimeSprite.addChild(this._leftTimeView);
            }
            return this._leftTimeSprite;
        }

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_descTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_leftTimeSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_leftTimeView: SecTimerView;

        /* internal */ /* var */_buffInfo: BuffInfo;

        /* internal */ /* var */_tstate: TState;
    }
